<?php
class View_upload_image_product extends View_Admin_Index_Template  {
	public $oTemp;
	public function __construct($oModel){
	}
	public function displayManagerIndex($oModel){
		$this->initTemplate($oModel);
		$this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/upload_image_product.html' );	
		$this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['upload_image_product_detail']);
		/**
		 * toolbar setup
		 */	
		$this->oTemp->assign('toobar_save','back_to_edit_page()');
		$this->oTemp->assign_file('temp_product_js',PATH_TEMPLATE_ADMIN.'html/product_js.html' );
		$this->oTemp->parse('main.toobar_save');
		$this->oTemp->assign('toobar_cancel','?sMod=product_index&sAction=edit_form&id='.$_REQUEST['pictures_product_id']);
		$this->oTemp->parse('main.toobar_cancel');
	}

public function displayListImageUploaded($oModel){
	$getAllImage_db = $oModel->getAllImage_db();
	if (is_array($getAllImage_db)) {
		foreach ($getAllImage_db as $item_Image)
		{
			$item_Image["pictures"] = show_Picture_2($item_Image["pictures_file_name"],$item_Image["pictures_id"]);
			$this->oTemp->assign("LIST_PRODUCT_EXIST",$item_Image);
			$this->oTemp->parse('main.PRODUCT_EXIST.LIST_PRODUCT_EXIST');
			
		}
		$this->oTemp->parse('main.PRODUCT_EXIST');
	}
}
public function listImageOfThisP($oModel,$pictures_product_id){
	if (trim($pictures_product_id)=='') {
		return null;
		}
	$getAllImage_db = $oModel->getImage($pictures_product_id);
	$count = 0;
	$i=0;
	if (is_array($getAllImage_db)) {
		$count = count($getAllImage_db);
		foreach ($getAllImage_db as $item_Image)
		{
			$i++;
			$item_Image["pictures"] = show_Picture($item_Image["pictures_file_name"]);
			$item_Image["i"] = $i;
			$this->oTemp->assign("IMAGE_PRODUCT",$item_Image);
			$this->oTemp->parse('main.LIST_IMAGE_PRODUCT.IMAGE_PRODUCT');
			
		}
		$this->oTemp->parse('main.LIST_IMAGE_PRODUCT');
	}
	$this->oTemp->assign("count_current_image",$count);
	
	}
public function resultXML_AddImageProduct($oModel,$pictures_id,$product_id){
		if (trim($pictures_id)!='' && trim($product_id)!='') {			 
			$aData = array("pictures_id"=>$pictures_id,"pictures_product_id"=>$product_id);
			$doUpdate= $oModel->doUpdateImagesItemProduct($aData);
			$rerult = $oModel->getImage($product_id);
			}
		$count = 0;        
        $RES='';
        if (is_array($rerult)) {
			$count = count($rerult);
			foreach ($rerult as $item_Image)
			{
				$item_Image["pictures"] = show_Picture($item_Image["pictures_file_name"]);
				$this->oTemp->assign("IMAGE_PRODUCT",$item_Image);
				$this->oTemp->parse('main.LIST_IMAGE_PRODUCT.IMAGE_PRODUCT');
			}
		$this->oTemp->parse('main.LIST_IMAGE_PRODUCT');	
		$RES = $this->oTemp->text('main.LIST_IMAGE_PRODUCT');
        }
	    $oJSON = new Services_JSON() ;
	  	echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
		  			  'BODY' => array('RES' => $RES,
		  			  				   'count_image' => $count,
		  			  				  )) ) ;
	
	}
public function resultXML_deleteImageList($oModel,$pictures_id,$product_id,$pictures_file_name){
		$aData = array("pictures_id"=>$pictures_id,"pictures_product_id"=>$product_id,"pictures_file_name"=>$pictures_file_name);
		$doUpdate= $oModel->deleteImageList($aData);
	    
		$rerult = $oModel->getImage($product_id);
		$count = 0;        
        $RES='';
        if (is_array($rerult)) {
			$count = count($rerult);
			foreach ($rerult as $item_Image)
			{
				$item_Image["pictures"] = show_Picture($item_Image["pictures_file_name"]);
				$this->oTemp->assign("IMAGE_PRODUCT",$item_Image);
				$this->oTemp->parse('main.LIST_IMAGE_PRODUCT.IMAGE_PRODUCT');
			}
		$this->oTemp->parse('main.LIST_IMAGE_PRODUCT');	
		$RES = $this->oTemp->text('main.LIST_IMAGE_PRODUCT');
        }
	    $oJSON = new Services_JSON() ;
	  	echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
		  			  'BODY' => array('RES' => $RES,
		  			  				   'count_image' => $count,
		  			  				  )) ) ;
	
	}
public function resultXML_filter_image($oModel,$aData){	    
		$rerult = $oModel->filter_image($aData);
		$count = 0;        
        $RES= '';
        if (is_array($rerult)) {
				$count = count($rerult);
			foreach ($rerult as $item_Image)
				{
					$item_Image["pictures"] = show_Picture_2($item_Image["pictures_file_name"],$item_Image["pictures_id"]);
					$this->oTemp->assign("LIST_PRODUCT_EXIST",$item_Image);
					$this->oTemp->parse('main.PRODUCT_EXIST.LIST_PRODUCT_EXIST');
					
				}
				$this->oTemp->parse('main.PRODUCT_EXIST');
				$RES = $this->oTemp->text('main.PRODUCT_EXIST');
       	 }
	    $oJSON = new Services_JSON() ;
	  	echo $oJSON->encode( array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m'), ),
		  			  'BODY' => array('RES' => $RES,
		  			  				  )) ) ;
	
	}
/*
//19th april
//End class 
*/
}
?>